package impl;


import interfaces.ChatProxy;
import interfaces.ClientProxy;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

/**
 * Methodimplementation of chatproxy.
 * Implements methods for client to communicate with server
 *
 * @author Dominik Korittki
 * @author Steffen Grushka
 * @version 0.1
 */
public class ChatProxyImpl extends UnicastRemoteObject implements ChatProxy {

	private static final long serialVersionUID = 1L;
	private String username;
	private ClientProxy clientproxy;
	private ChatServerImpl chatserver;
	
	/**
	 * Creates a chatobject for a client
	 * @param username name of client
	 * @param clientproxy clientproxy object of client
	 * @param chatserver chatserver object
	 * @throws RemoteException
	 */
	public ChatProxyImpl(String username, ClientProxy clientproxy, ChatServerImpl chatserver) throws RemoteException {
		super();
		this.clientproxy = clientproxy;
		this.username = username;
		this.chatserver = chatserver;
	}

	@Override
	public void sendMessage(String message) throws RemoteException {
		chatserver.spreadMessage(username, message);
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public ClientProxy getClientproxy() {
		return clientproxy;
	}

	public void setClientproxy(ClientProxy clientproxy) {
		this.clientproxy = clientproxy;
	}

}
